package com.atguigu.yygh.order.config;
/**
 * 生产者
 */

import com.atguigu.yygh.mq.constant.MessageQueueContant;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ExchangeQueueConfig {

    @Bean(value = "exchange") //指定交换机在ioc容器中的名字
    public Exchange getExchange(){
        return ExchangeBuilder.topicExchange(MessageQueueContant.EXCHANGE_ORDER).build(); //得到一个交换机对象
    }

    @Bean(value = "queue")
    public Queue getQueue(){
        return QueueBuilder.durable(MessageQueueContant.QUEUE_ORDER).build(); //得到一个队列
    }

    //将队列绑定到交换机上
    @Bean
    public Binding bingQueueToExchange(@Qualifier("queue") Queue queue, @Qualifier("exchange") Exchange exchange){
       return BindingBuilder.bind(queue).to(exchange).with("order.#").noargs(); //order.#表示以order开头
    }
}